package com.zhanghe.study.design_pattern.iterator_pattern;

/**
 * @author zh
 * @date 2022/10/14 14:45
 */
public class ConcreteCollection<E> implements Collection<E>{

    // 元素
    private E[] arrays;

    public ConcreteCollection(E[] arrays){
        this.arrays = arrays;
    }

    @Override
    public Iterator<E> iterator() {
        // 实例化迭代器
        return new ConcreteIterator<>(this);
    }

    // 根据索引位置获取元素
    public E get(int index){
        E ele = null;
        if(index < arrays.length){
            ele = arrays[index];
        }
        return ele;
    }

    public int size(){
        return arrays.length;
    }
}
